package com.ruoyi.car.controller.part;

import com.car.pojo.TPartPatternAssembly;
import com.car.pojo.TPartPatternAssemblyModel;
import com.ruoyi.car.service.BatteryServiceinter;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/cpart/battery")
public class PartController extends BaseController {
    String prefix="/car/cpart";
    @Autowired
    private BatteryServiceinter batteryServiceinter;
    @RequiresPermissions("cpart:battery:vidio")
    @GetMapping()
    public String assembly()
    {
        return prefix + "/batterygroup";
    }

    @RequiresPermissions("cpart:battery:model")
    @GetMapping(value = "/model")
    public String model()
    {
        return prefix + "/batterymodel";
    }
    //隔绝一手


    @RequiresPermissions("cpart:battery:grouplist")
    @PostMapping("/grouplist")
    @ResponseBody
    public TableDataInfo battery(Model model){
        startPage();
        List<TPartPatternAssembly> allpatternAssmbly = batteryServiceinter.findAllpatternAssmbly();
        //model.addAttribute("battery",allpatternAssmbly);
        return getDataTable(allpatternAssmbly);
    }
    @RequiresPermissions("cpart:battery:modellist")
    @PostMapping("/modellist")
    @ResponseBody
    public TableDataInfo batterymodel(Model model){
        startPage();
        List<TPartPatternAssemblyModel> allpatternAssmbly = batteryServiceinter.findAllpatternAssmblyModel();
        //model.addAttribute("battery",allpatternAssmbly);
        return getDataTable(allpatternAssmbly);
    }


    /**
     * 新增电池模组信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }
    @GetMapping("/addmodel")
    public String addModel()
    {
        return prefix + "/addmodel";
    }

    /**
     * 新增保存电池模组信息
     */
    @RequiresPermissions("cpart:battery:add")
    @Log(title = "电池模组信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TPartPatternAssembly tPartPatternAssembly)
    {
        return toAjax(batteryServiceinter.addSave(tPartPatternAssembly));
    }
    @RequiresPermissions("cpart:battery:addmodel")
    @Log(title = "电池模组型号", businessType = BusinessType.INSERT)
    @PostMapping("/addmodel")
    @ResponseBody
    public AjaxResult addSaveModel(TPartPatternAssemblyModel tPartPatternAssemblyModel)
    {
        return toAjax(batteryServiceinter.addSaveModel(tPartPatternAssemblyModel));
    }

    /**
     * 修改电池模组信息
     */
    @GetMapping("/edit/{patternAssemblyId}")
    public String edit(@PathVariable("patternAssemblyId") String patternAssemblyId, ModelMap mmap)
    {
        TPartPatternAssembly tPartPatternAssembly = batteryServiceinter.selectTPartPatternAssemblyById(patternAssemblyId);
        mmap.put("tPartPatternAssembly", tPartPatternAssembly);
        return prefix + "/edit";
    }
    @GetMapping("/editmodel/{patternAssemblyId}")
    public String editmodel(@PathVariable("patternAssemblyId") String patternAssemblyId, ModelMap mmap)
    {
        TPartPatternAssemblyModel tPartPatternAssembly = batteryServiceinter.selectTPartPatternAssemblyModelById(patternAssemblyId);
        mmap.put("tPartPatternAssemblyModel", tPartPatternAssembly);
        return prefix + "/editmodel";
    }


    //查看详细参数
    @GetMapping("/svalue/{patternAssemblyId}")
    public String svalue(@PathVariable("patternAssemblyId") String patternAssemblyId, ModelMap mmap)
    {
        TPartPatternAssembly tPartPatternAssembly = batteryServiceinter.selectTPartPatternAssemblyById(patternAssemblyId);
        mmap.put("tPartPatternAssembly", tPartPatternAssembly);
        return prefix + "/svalue";
    }

    /**
     * 修改保存电池模组信息
     */
    @RequiresPermissions("cpart:battery:edit")
    @Log(title = "电池模组信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TPartPatternAssembly tPartPatternAssembly)
    {
        return toAjax(batteryServiceinter.updateTPartPatternAssembly(tPartPatternAssembly));
    }
    @RequiresPermissions("cpart:battery:editmodel")
    @Log(title = "电池模组型号", businessType = BusinessType.UPDATE)
    @PostMapping("/editmodel")
    @ResponseBody
    public AjaxResult editModelSave(TPartPatternAssemblyModel tPartPatternAssemblyModel)
    {
        return toAjax(batteryServiceinter.updateTPartPatternAssemblyModel(tPartPatternAssemblyModel));
    }

    /**
     * 删除电池模组信息
     */
    @RequiresPermissions("cpart:battery:remove")
    @Log(title = "电池模组信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(batteryServiceinter.deleteTPartPatternAssemblyByIds(ids));
    }
    @RequiresPermissions("cpart:battery:removemodel")
    @Log(title = "电池模组型号", businessType = BusinessType.DELETE)
    @PostMapping( "/removemodel")
    @ResponseBody
    public AjaxResult removemodel(String ids)
    {
        return toAjax(batteryServiceinter.deleteTPartPatternAssemblyModelByIds(ids));
    }


}
